package com.igeek.base.ch0712.Demo3;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;


/**
 * @Description TODO
 * @Author chenmin
 * @Date 2024/7/14 13:30
 */
public class Text {
    public static void main(String[] args) {
        Shape[] shapes ={
                new Circle(5.0),
                new Circle(3.0),
                new Rectangle(4.0, 6.0),
                new Rectangle(2.0, 8.0)
        };

        System.out.println("--------------------图形的面积进行升序排序-----------------------------");
        sortByArea(shapes);
        for (Shape shape : shapes) {
            System.out.println(shape + ", 面积= " + shape.getArea() + ", 周长= " + shape.getSize());
        }

        System.out.println("--------------------图形的周长进行降序排序-----------------------------");
        sortBySize(shapes);
        for (Shape shape : shapes) {
            System.out.println(shape + ", 面积= " + shape.getArea() + ", 周长=" + shape.getSize());
        }

    }
    public static void sortByArea(Shape[] shapes){
        Arrays.sort(shapes);
    }
    public static void sortBySize(Shape[] shapes){
        Arrays.sort(shapes, Comparator.comparingDouble(Shape::getSize).reversed());
    }
}
